<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="姓名">
              <a-input placeholder="请输入姓名" v-model="queryParam.userName"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="联系方式">
              <a-input placeholder="请输入联系方式" v-model="queryParam.mobile"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-button @click="() => {this.queryPage()}" type="primary">查询</a-button>
            <a-button @click="() =>{ queryParam = {}}" style="margin-left: 8px">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div class="table-operator">
      <!--  <a-button @click="(e) => this.goToUpload()" style="margin-bottom: 8px">
         导入
       </a-button> -->

      <a-button @click="(e) => this.goToAdd()" style="margin-bottom: 8px;margin-left: 6px;" type="primary">
        新增
      </a-button>
    </div>
    <v-table
      :table-column="columns"
      :data="loadData"
      :rowKey="record => record.id"
      bordered
      ref="table"
    >
      <template v-slot:action='{ text, row }'>
        <div class="actionColumn">
          <span>
            <a-divider type='vertical'/>
            <a href='javascript:' @click='show(row)'>查看</a>
          </span>
          <span>
            <a-divider type='vertical'/>
            <a href='javascript:' @click='update(row)'>编辑</a>
          </span>
          <span>
            <a-divider type='vertical'/>
            <a-popconfirm title='是否删除' @confirm='deleteItem(row)' okText='是' cancelText='否'>
              <a-icon slot='icon' type='question-circle-o' style='color: red'/>
              <a href='javascript:' style='color: red'>删除</a>
            </a-popconfirm>
          </span>
        </div>
      </template>
    </v-table>
    <!--    <Wfudevice-upload-->
    <!--      @ok="queryPage"-->
    <!--      ref="WfudeviceUpload">-->
    <!--    </Wfudevice-upload>-->
    <wfu-student-add-or-update
      @ok="queryPage"
      ref="editor">
    </wfu-student-add-or-update>
  </a-card>
</template>

<script>
import {delObj, fetchList} from "@api/wfuStudent/student";
import {TableMixin} from "@/mixins/TableMixin";
import WfuStudentAddOrUpdate from "@views/modules/wfucheck/wfuStudent/WfuStudentAddOrUpdate";

export default {
  name: "wfuStudent",
  components: {WfuStudentAddOrUpdate},
  comments: {
    WfuStudentAddOrUpdate
  },
  mixins: [TableMixin],
  data() {
    return {
      columns: [
        {
          title: '钉钉ID',
          field: 'userId'
        },
        {
          title: '学号',
          field: 'userCode'
        },
        {
          title: '姓名',
          field: 'userName'
        },
        {
          title: '联系方式',
          field: 'mobile'
        },
        {
          title: '学院',
          field: 'institute'
        },
        {
          title: '专业班级',
          field: 'major'
        },
        {
          title: '导员姓名',
          field: 'assistantName'
        },
        {
          title: '导员电话',
          field: 'assistantMobile'
        },
        {
          title: '操作',
          width: '200px',
          field: 'action',
          fixed: 'right',
          slot: true
        }
      ],
      queryParam: {
        mobile: '',
        assistantMobile: '',
        assistantName: '',
        institute: '',
        userCode: '',
        userId: '',
        userName: '',
        major: '',
      },
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    goToAdd() {
      this.$refs.editor.edit(null, 'add')
    },
    handleChange(info) {
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList)
      }
      if (info.file.status === 'done') {
        if (info.file.response.code === 0) {
          this.$message.success('导入成功！')
          this.init()
        } else if (info.file.response.code === 1) {
          this.$message.error(info.file.response.msg)
        }
        this.queryPage()
      } else if (info.file.status === 'error') {
        this.$message.error('导入失败，请重试！')
      }
    },
    show(record) {
      this.$refs.editor.edit(record.id, 'show')
    },
    update(record) {
      this.$refs.editor.edit(record.id, 'edit')
    },
    deleteItem(record) {
      delObj(record.id).then(res => {
        if (res.code === 0) {
          this.$message.info('删除成功')
          this.queryPage()
        } else {
          this.$message.warn(res.massage)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>